package com.woniu.shop.mapper;

import com.woniu.shop.pojo.ShopIncome;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.shop.pojo.ShopIncome;
import com.woniu.shop.pojo.ShopYearIncome;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 门店收益表 Mapper 接口
 * </p>
 *
 * @author LiFangyu
 * @since 2023-02-15
 */

public interface ShopIncomeMapper extends BaseMapper<ShopIncome> {

    @Select("select amount from t_shop_year_income where shop_id = #{shopId} and year = #{year}")
    @ResultType(BigDecimal.class)
    BigDecimal selectShopIncomeInYear(@Param("shopId") String shopId,@Param("year") String year);

    @Select("select distinct shop_id from t_shop_income ")
    @ResultType(String.class)
    List<String> getAllShopId();

    @Insert("insert into t_shop_year_income value (#{id},#{shopId},#{year},#{amount},#{isDeleted},#{createdTime},#{updatedTime})")
    void createShopYearIncome(ShopYearIncome shopYearIncome);

    @Update("update t_shop_year_income set amount = #{amount} , updated_time = #{updatedTime}")
    void updateShopYearIncome(ShopYearIncome shopYearIncome);

    @Select("select * from t_shop_year_income where shop_id = #{shopId} and year = #{year}")
    @ResultType(ShopYearIncome.class)
    ShopYearIncome checkRecordExist(@Param("shopId") String shopId,@Param("year") String year);

    @Select("select cron from t_shop_cron where execute_class = #{executeClass}")
    @ResultType(String.class)
    String getCron(String executeClass);

    @Select("select date_format(created_time,'%Y') `year` from t_shop_income where shop_id = #{shopId} group by date_format(created_time,'%Y')")
    List<String> getAllYear(String shopId);

    @Select("select * from t_shop_income where shop_id = #{shopId} and date_format(created_time,'%Y') = #{year}")
    List<ShopIncome> getIncomeRecord(@Param("shopId") String shopId,@Param("year") String year);

}
